
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class HelloServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
    public void init(ServletConfig config){
        System.out.println("init of Hello Servlet");
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response){
		Enumeration<String> headerNames = request.getHeaderNames();
//		System.out.println("浏览器："+request.getHeader("user-agent"));
        while(headerNames.hasMoreElements()){
            String header = headerNames.nextElement();
            String value = request.getHeader(header);
//            System.out.printf("%s\t%s%n",header,value);
        }
        try {
        	HttpSession	session = request.getSession();
        	System.out.println("sessionId:"+session.getId());
        	response.setDateHeader("Expires",0 );
        	response.setHeader("Cache-Controll","no-cache");
        	response.setHeader("pragma","no-cache");
            response.getWriter().println("<h1>Hello Servlet!</h1>");
            response.getWriter().println(new Date().toLocaleString());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	}

}
	